package common;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class JPanelAnimated extends JPanel implements MouseListener{
	private StringBuilder titleBorder;
	private Dimension minSize;
	private Dimension maxSize;

	private boolean clicked = true;
	private boolean animated = false;
	
	public JPanelAnimated() {
		super(); 
		this.addMouseListener(this);
		titleBorder = new StringBuilder();
	}
	
	public String getTitleBorder() {
		return titleBorder.toString();		
	}

	public void setTitleBorder(String titleBorder) {
		this.titleBorder = new StringBuilder(titleBorder);
		this.setBorder(BorderFactory.createTitledBorder(getTitleBorder()));
	}
	
	public void setAnimated(boolean animated) {
		this.animated = animated;
	}

	public Dimension getMinSize() {
		return minSize;
	}

	public void setMinSize(Dimension minSize) {
		this.minSize = minSize;
	}

	public Dimension getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(Dimension maxSize) {
		this.maxSize = maxSize;
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		if (animated){
			System.out.println(e.getClickCount());
			if (e.getClickCount() >= 2){
				JPanel doubleClick = (JPanel) e.getSource();
				String operation; 
				
				if(clicked){
					doubleClick.setPreferredSize(new Dimension(300,20));
					operation = "+";
				}else{
					doubleClick.setPreferredSize(new Dimension(300,200));
					operation = "-";
				}
				doubleClick.setBorder(BorderFactory.createTitledBorder(operation + " " + titleBorder.toString()));
				clicked = !clicked;	
				doubleClick.updateUI();
			}
		}
	}


	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	
	}
}
